package com.mbc.mapper;


import com.mbc.pojo.MbcFans;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;


/**
 * 粉丝映射器
 *
 * @author suimeng
 * @date 2024/04/08
 */
@Mapper
public interface FansMapper {
    /**
     * 通过用户 ID 分页查询粉丝列表
     *
     * @param userId 用户 ID
     * @return {@link List}<{@link MbcFans}>
     */
    @Select("select * from mbc_fans where user_id = #{userId}")
    List<MbcFans> getAllByUserId(String userId);

    /**
     * 分页新增粉丝列表
     *
     * @param userId 用户 ID
     * @param now    现在
     * @return {@link List}<{@link MbcFans}>
     */
    @Select("select * from mbc_fans where create_time >= DATE_SUB(#{now},interval 7 DAY) and user_id = #{userId}")
    List<MbcFans> getAddFansList(String userId, LocalDateTime now);

    /**
     * 删除粉丝取消关注
     *
     * @param fansId 粉丝 ID
     * @return int
     */
    @Delete("delete from mbc_fans where fans_id = #{fansId}")
    int deleteFansUnfollow(String fansId);

    /**
     * 新增粉丝
     *
     * @param userId 用户 ID
     * @param fansId 粉丝 ID
     * @param now    现在
     * @return int
     */
    @Insert("insert into mbc_fans(user_id, fans_id, create_time) values (#{userId},#{fansId},#{now})")
    int insertFans(String userId, String fansId, LocalDateTime now);
}
